home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / compress / arc.zoo / arcmatch.c < prev    next >
C/C++ Source or Header  |  1989-01-29  |  3KB  |  141 lines

  1. /*
  2.  * $Header: arcmatch.c,v 1.6 88/07/31 18:50:18 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCMATCH
  7.  * 
  8.  * Version 2.17, created on 12/17/85 at 20:32:18
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains service routines needed to maintain an
  15.  * archive.
  16.  * 
  17.  * Language: Computer Innovations Optimizing C86
  18.  */
  19. #include <stdio.h>
  20. #include "arc.h"
  21.  
  22. #ifndef __STDC__
  23. int    strcmp(), strlen();
  24. #endif
  25. void    abort();
  26. #ifndef __STDC__
  27. char    *strcpy();
  28. #endif
  29.  
  30. int
  31. match(n, t)            /* test name against template */
  32.     char           *n;    /* name to test */
  33.     char           *t;    /* template to test against */
  34. {
  35. #if    MTS
  36.     fortran         patbuild(), patmatch(), patfree();
  37.     static int      patlen = (-1);
  38.     static int      patwork = 0;
  39.     static int      patswch = 0;
  40.     char            patccid[4];
  41.     static char     patchar[2] = "?";
  42.     static char     oldtemp[16] = 0;
  43.     int             namlen, RETCODE;
  44.  
  45.     if (strcmp(t, oldtemp)) {
  46.         if (patwork)
  47.             patfree(&patwork);
  48.         strcpy(oldtemp, t);
  49.         patlen = strlen(oldtemp);
  50.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  51.         if (RETCODE > 8) {
  52.             printf("MTS: patbuild returned %d\n", RETCODE);
  53.             abort("bad wildcard in filename");
  54.         }
  55.     }
  56.     namlen = strlen(n);
  57.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  58.     switch (RETCODE) {
  59.     case 0:
  60.         return (1);
  61.     case 4:
  62.         return (0);
  63.     default:
  64.         abort("wildcard pattern match failed");
  65.     }
  66. }
  67.  
  68. #else
  69. #if    !UNIX
  70.     upper(n);
  71.     upper(t);        /* avoid case problems */
  72. #endif    /* UNIX */
  73. #if    GEMDOS
  74.     char *strstr(), *i;    /* allow "*.*" to mean '*' */
  75.     if (i=strstr(t,"*.*")) {
  76.         i++;
  77.         *i='\0';
  78.     }
  79.     return(pnmatch(n, t, 0));
  80. #else
  81.     /* first match name part */
  82.  
  83.     while ((*n && *n != '.') || (*t && *t != '.')) {
  84.         if (*n != *t && *t != '?') {    /* match fail? */
  85.             if (*t != '*')    /* wildcard fail? */
  86.                 return 0;    /* then no match */
  87.             else {    /* else jump over wildcard */
  88.                 while (*n && *n != '.')
  89.                     n++;
  90.                 while (*t && *t != '.')
  91.                     t++;
  92.                 break;    /* name part matches wildcard */
  93.             }
  94.         } else {    /* match good for this char */
  95.             n++;    /* advance to next char */
  96.             t++;
  97.         }
  98.     }
  99.  
  100.     if (*n && *n == '.')
  101.         n++;        /* skip extension delimiters */
  102.     if (*t && *t == '.')
  103.         t++;
  104.  
  105.     /* now match name part */
  106.  
  107.     while (*n || *t) {
  108.         if (*n != *t && *t != '?') {    /* match fail? */
  109.             if (*t != '*')    /* wildcard fail? */
  110.                 return 0;    /* then no match */
  111.             else
  112.                 return 1;    /* else good enough */
  113.         } else {    /* match good for this char */
  114.             n++;    /* advance to next char */
  115.             t++;
  116.         }
  117.     }
  118.  
  119.     return 1;        /* match worked */
  120. #endif    /* GEMDOS */
  121. }
  122. #endif
  123.  
  124. void
  125. rempath(nargs, arg)        /* remove paths from filenames */
  126.     int             nargs;    /* number of names */
  127.     char           *arg[];    /* pointers to names */
  128. {
  129.     char           *i, *rindex();    /* string index, reverse indexer */
  130.     int             n;    /* index */
  131.  
  132.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  133.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  134.                              * path */
  135.             if (!(i = rindex(arg[n], '/')))
  136.                 i = rindex(arg[n], ':');
  137.         if (i)        /* if path was found */
  138.             arg[n] = i + 1;    /* then skip it */
  139.     }
  140. }
  141.